package sdk.webview.fmc.com.fmcsdk.view;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;

import sdk.webview.fmc.com.fmcsdk.R;


/**
 * 自定的dialog提示框，包括GPS开关，清理缓存，更新APK1s
 */
public class BluetoothDialog extends Dialog {
	private Context context;
	/**标题和内容*/
	private String msg,title;
	/**是否是清理缓存打开的提示框*/
	private boolean isClearData = false;
	private ClickListenerInterface clickListenerInterface;
	private TextView confirm;
	private TextView tv_message;
	private View view;

	//只有提示内容的消息框
	public BluetoothDialog(Context context, String msg) {
		super(context, R.style.Dialog);
		this.context = context;
		this.msg = msg;
	}
	//带有自定义标题的提示框
	public BluetoothDialog(Context context, String title, String msg) {
		super(context, R.style.Dialog);
		this.context = context;
		this.msg = msg;
		this.title = title;
		isClearData = true;
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.bluetooth_dialog);
		confirm = (TextView) findViewById(R.id.confirm);
		tv_message = (TextView) findViewById(R.id.tv_message);
		tv_message.setText(msg);
		confirm.setOnClickListener(new clickListener());
		//试着提示框的位置和大小
		Window dialogWindow = getWindow();
		WindowManager.LayoutParams lp = dialogWindow.getAttributes();
		DisplayMetrics d = context.getResources().getDisplayMetrics(); // 获取屏幕宽、高
		lp.width = (int) (d.widthPixels * 0.9);
		dialogWindow.setAttributes(lp);

	}

	public void setConfirmText(String text){
		confirm.setText(text);
	}
	public void setMessageText(String text){
		tv_message.setText(text);
	}
	public void setClicklistener(ClickListenerInterface clickListenerInterface) {
		this.clickListenerInterface = clickListenerInterface;
	}


	private class clickListener implements View.OnClickListener {
		@Override
		public void onClick(View v) {
			int id = v.getId();
			if (id==R.id.confirm){
				clickListenerInterface.doConfirm();
			}

		}

	}


	public interface ClickListenerInterface {

		void doConfirm();
	}

}
